#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int coinChange(vector<int>& coins, int amount) {
        vector<int>ans(amount+1,amount+1);
        ans[0]=0;
        for(int i=1;i<ans.size();i++)
        {
            for(int j=0;j<coins.size();j++)
            {
                if(coins[j]>i)continue;
                ans[i]=min(ans[i],ans[i-coins[j]]+1);
            }
        }
        if(ans[amount]==amount+1)return -1;
        return ans[amount];
    }
};